import axios from 'axios';

// 获取任务大厅数据
export const getTaskLobby = async (page = 1, pageSize = 10, filters = {}) => {
    try {
        const { money_start, money_end, start_time, end_time, address, status, title, type } = filters;
        const response = await axios.get('http://10.33.16.198:18080/tasks/lobby', {
            params: {
                page,
                pagesize: pageSize,
                money_start,
                money_end,
                start_time,
                end_time,
                address,
                status,
                title,
                type,
            },
        });

        if (response.data.code === 200) {
            return response.data.data.taskLobbyVos; // 返回任务数据
        } else {
            throw new Error(response.data.msg || '接口返回错误');
        }
    } catch (error) {
        console.error('请求失败:', error);
        const errorMessage = error.message || '未知错误';
        throw new Error(errorMessage);
    }
};

// 更新任务状态
export const updateTaskStatus = async (taskId, newStatus) => {
    try {
        const response = await axios.post('http://10.33.16.198:18080/tasks/updateStatus', {
            taskId,
            status: newStatus,
        });

        if (response.data.code === 200) {
            return response.data.data; // 更新成功
        } else {
            throw new Error(response.data.msg || '任务状态更新失败');
        }
    } catch (error) {
        console.error('更新状态失败:', error);
        throw new Error(error.message || '任务状态更新失败');
    }
};


// 如果你有其他接口，可以在这里继续添加
